package com.bnz.portal.controller;

import com.bnz.common.entity.R;
import com.bnz.portal.client.UserClient;
import com.bnz.portal.entity.ContentEntity;
import com.bnz.portal.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
//@RefreshScope
public class PortalController {
    @Autowired
    private ContentService contentService;

    @Autowired
    private UserClient userClient;
    //1. 欢迎页面
    @GetMapping({"/", "/index.html"})
    public String index(Model model) {
        List<ContentEntity> list = contentService.findAll();
        model.addAttribute("contents", list);
        return "index";
    }


    @GetMapping("/list")
    @ResponseBody
    public R list(){
        return R.ok().put("list",contentService.list());
    }
    //1. 通过portal模块得到所有用户的列表
    @GetMapping("/portal/user/list")
    @ResponseBody
    public R findUsers(){
        return userClient.findAll();
    }

    //2. 根据用户id查询单个用户
    @GetMapping("/portal/user/findById/{id}")
    @ResponseBody
    public R findUserById(@PathVariable String id){
        return userClient.findById(id);
    }
}
